package com.attendancesystem.model;

import java.math.BigDecimal;
import java.time.LocalDateTime;

public class AttendanceDetails {
    private Integer attendanceDetailId;
    private LocalDateTime attendanceDetailTime;
    private String attendanceDetailClass;
    private String attendanceDetailCourse;
    private Integer attendanceDetailPerson;
    private Integer attendanceDetailActual;
    private BigDecimal attendanceDetailRate;
    private AttendanceStatus attendanceDetailEnum;

    // 枚举类型定义
    public enum AttendanceStatus {
        PENDING("待开始"),
        COMPLETED("已结束"),
        CANCELED ("已取消");

        private final String statusCode;

        AttendanceStatus(String statusCode) {
            this.statusCode = statusCode;
        }

        public String getStatusCode() {
            return statusCode;
        }
        public static AttendanceStatus AttendanceDetailFromChineseName(String chineseName) {
            for ( AttendanceStatus attendanceStatus: values()) {
                if (attendanceStatus.statusCode.equals(chineseName)) {
                    return attendanceStatus;
                }
            }
            throw new IllegalArgumentException("无效的状态值: " + chineseName);
        }
    }

    // Getters and Setters
    public Integer getAttendanceDetailId() {
        return attendanceDetailId;
    }

    public void setAttendanceDetailId(Integer attendanceDetailId) {
        this.attendanceDetailId = attendanceDetailId;
    }

    public LocalDateTime getAttendanceDetailTime() {
        return attendanceDetailTime;
    }

    public void setAttendanceDetailTime(LocalDateTime attendanceDetailTime) {
        this.attendanceDetailTime = attendanceDetailTime;
    }

    public String getAttendanceDetailClass() {
        return attendanceDetailClass;
    }

    public void setAttendanceDetailClass(String attendanceDetailClass) {
        this.attendanceDetailClass = attendanceDetailClass;
    }

    public String getAttendanceDetailCourse() {
        return attendanceDetailCourse;
    }

    public void setAttendanceDetailCourse(String attendanceDetailCourse) {
        this.attendanceDetailCourse = attendanceDetailCourse;
    }

    public Integer getAttendanceDetailPerson() {
        return attendanceDetailPerson;
    }

    public void setAttendanceDetailPerson(Integer attendanceDetailPerson) {
        this.attendanceDetailPerson = attendanceDetailPerson;
    }

    public Integer getAttendanceDetailActual() {
        return attendanceDetailActual;
    }

    public void setAttendanceDetailActual(Integer attendanceDetailActual) {
        this.attendanceDetailActual = attendanceDetailActual;
    }

    public BigDecimal getAttendanceDetailRate() {
        return attendanceDetailRate;
    }
    public void setAttendanceDetailRate(BigDecimal attendanceDetailRate) {
        this.attendanceDetailRate = attendanceDetailRate;
    }

    // 生成字段不需要setter
    public AttendanceStatus getAttendanceDetailEnum() {
        return attendanceDetailEnum;
    }

    public void setAttendanceDetailEnum(AttendanceStatus attendanceDetailEnum) {
        this.attendanceDetailEnum = attendanceDetailEnum;
    }
    @Override
    public String toString() {
        return String.format(
                "AttendanceDetails{id=%d, time=%s, class='%s', course='%s', 应到=%d, 实到=%d, 出勤率=%.2f%%, 状态=%s}",
                attendanceDetailId,
                attendanceDetailTime != null ? attendanceDetailTime.toString() : "null",
                attendanceDetailClass,
                attendanceDetailCourse,
                attendanceDetailPerson,
                attendanceDetailActual,
                attendanceDetailRate != null ? attendanceDetailRate : 0,
                attendanceDetailEnum != null ? attendanceDetailEnum.name() : "null"
        );
    }
}
